package fms.webservice.server.dao;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.util.*;

public class ResultSetToList {
	public static List resultSetToList(ResultSet rs) throws java.sql.SQLException, IOException {   
        if (rs == null)   
            return Collections.EMPTY_LIST;   
        ResultSetMetaData md = rs.getMetaData();
        int columnCount = md.getColumnCount();
        List list = new ArrayList();   
        Map rowData = new HashMap();   
        while (rs.next()) {   
         rowData = new HashMap(columnCount);   
         for (int i = 1; i <= columnCount; i++) {   	 
        	 rowData.put(md.getColumnName(i), rs.getObject(i));
//             System.out.println(rs.getObject(i)); 
         }   
         list.add(rowData);   
         //System.out.println("list:" + list.toString());
        }
        return list;   
	}  
}
